#include "support.h"

using namespace tp1;

Support::Support(float base,float height,float radiusCylinders,int sidesCylinders)
	:Object3D(m_base+4*radiusCylinders)
{
	m_base = base;
	m_height = height;

	m_radiusCylinders = radiusCylinders;
	m_sidesCylinders = sidesCylinders;

	m_pattern = new TrianglePattern(m_base,m_height,QOBLIQUECYLINDERS,m_radiusCylinders,m_sidesCylinders);
	m_cylinder = new Cylinder(m_radiusCylinders,base,m_sidesCylinders);
}


Support::~Support(void)
{
	delete m_pattern;
	delete m_cylinder;
}


void Support::Render()
{
	
		
	glPushMatrix();
		glTranslatef(0,(m_base+m_pattern->Width())/2.0f,0);
		glPushMatrix();		
			m_pattern->Render();
			glPushMatrix();
			m_pattern->Translate(0,-(m_base+m_pattern->Width()),0);
			m_pattern->Render();
			glPopMatrix();
		glPopMatrix();

		//Cilindros que forman la base del soporte
		glPushMatrix();		
			m_cylinder->Rotate(90,1,0,0);
			glPushMatrix();
				m_cylinder->Translate(m_base/2.0f,-m_height,0);
				m_cylinder->Render();		
			glPopMatrix();
			m_cylinder->Translate(-m_base/2.0f,-m_height,0);
			m_cylinder->Render();	
		glPopMatrix();
	glPopMatrix();
}